var vm = new Vue({
	el:"#container",
			data:{
				orders:[],
				lists:[],
				totalCount:'',
				customers:'',
				echarts:'',
				memoName:'',
				remark:'',
				clientName:'',
				mobile:'',
				mobile2:'',
				pictrue:'',
				mess:'',
				birthday:'',
				gender:'',
				email:'',
				idStr:'',
				dynamics:'',
				page:1,
				pageCount:'',
				pictureUrl:'',
				myInvitationCode:'',
				myInvitationCodeImg:'',
				myInvitationName:'',
				name:'请登录',
				picture:'../../build/images/touxiang.png',
				file:'',
				image: '',
				data:'',
				mobile3:'',
				certificationStatus:'',
				userName:'',
				realNameVerified:'false',
				monthIncome:'0.00',
				withdrawalBalance:'0.00',

			},
			mounted:function(){
				this.$nextTick(function(){
					var pathname=location.pathname;
					if(! window.localStorage.getItem('X-Auth-Token')){
						vm.name="请登录"
						$('.go').click(function(event) {
							window.location.href="../../../pages/login/login.html"
						});
						$('.goIncome').click(function(event) {
							window.location.href="../../../pages/login/login.html"
						});
						$('.goWallet').click(function(event) {
							window.location.href="../../../pages/login/login.html"
						});
						$('.goSet').click(function(event) {
							window.location.href="../../../pages/login/login.html"
						});
						$('.goMess').click(function(event) {
							window.location.href="../../../pages/login/login.html"
						});
						$('.cus-no').show();
						$('.cus-in').hide();
						$('.change-yellow').addClass('gray-color');
						this.noRead();
						if(pathname=='/pages/mine/invite.html'){
							vm.myInvitationCodeImg="../../build/images/code.jpg"
						}
					}else{
						$('.go').click(function(event) {
							window.location.href="../../../pages/mine/edit.html"
						});
						$('.goIncome').click(function(event) {
							window.location.href="../../../pages/mine/income.html"
						});
						$('.goWallet').click(function(event) {
							window.location.href="../../../pages/mine/wallet.html"
						});
						$('.goSet').click(function(event) {
							window.location.href="../../../pages/mine/settings.html"
						});
						$('.goMess').click(function(event) {
							window.location.href="../../../pages/mine/message.html"
						});
						//客户列表数据
						if(pathname=='/pages/mine/customer.html'){
							this.customer();
							refresh(this.refreshData());
							//信息
							this.mineInfor();
							this.noRead();
						}
						if(pathname=='/pages/mine/invite.html'){
							vm.invite_code();
							//信息
							this.mineInfor();
							this.noRead();
						}
					}
					//客户详情
					if(pathname=='/pages/mine/customerDetail.html'){
						this.orderFunction('','');
						refresh(this.refreshData());
					}	
				})
			},
			methods:{
				// 未读消息数
				noRead:function(){
					noParamsGet('/advisor/msg/unread-count',function(res){
						vm.data=res.data;
						if(res.data>9){
							vm.data='9+';
							$('.mine-circle').show();
						}else if(res.data==0){
							$('.mine-circle').hide();
						}else{
							$('.mine-circle').show();
						}
					})
				},
				
				// 头部信息
				mineInfor:function () {
					noParamsGet('/user/info',function(res){
						vm.mobile=res.data.mobile ? res.data.mobile.replace(/^(\d{3})\d{4}(\d+)/,"$1****$2") : '';
						vm.name=res.data.name;
						vm.monthIncome = res.data.monthIncome ? res.data.monthIncome : '0.00';
						vm.withdrawalBalance  = res.data.withdrawalBalance ? res.data.withdrawalBalance : '0.00';
						vm.picture=res.data.picture ? res.data.picture : '../../build/images/touxiang.png';
						vm.realNameVerified=res.data.realNameVerified;
						if(vm.realNameVerified==false){
							$('.cel-yellow').addClass('gray-color');
							$('.cel-yellow').click(function(event) {
								window.location.href='noCard.html'
							});
						}
					});
				},

				// 客户列表
				customer:function(callback){
					loader.init();
					var $this = this;
					get('/order/client/list',{currentPage:vm.page},function(res){
						vm.lists=vm.lists.concat(res.data.resultList);
						vm.totalCount=res.data.totalCount;
						vm.pageSize=res.data.pageSize;
						vm.pageCount=Math.ceil(vm.totalCount / vm.pageSize);
						var len=vm.lists;
						for(i=0;i<len.length;i++){
							if(typeof len[i].picture!='undefined'){
								len[i].pictureUrl=domain+vm.lists[i].picture;
							}else{
								len[i].pictureUrl='/build/images/touxiang.png'
							}
							if(! len[i].totalAssets){
								vm.lists[i].totalAssets='0'
							}
						}
						//滚动到底部文字判断
						if(res.data.resultList.length < 10){
							refreshText('到底了哦！')
						}else{
							refreshText('上拉加载更多数据')
						}
						if(vm.totalCount == 0){
							$('.cus-no').show();
							$('.cus-in').hide();
							// document.querySelector('.empetDate').style.display = 'block';
							refreshText('')
						}else{
							$('.cus-no').hide();
							$('.cus-in').show();
							// document.querySelector('.empetDate').style.display = 'none';
						}
						if(vm.lists.length <20){
							refreshText('')
						}
						loader.remove();
					})
				},

				// 客户详情订单列表
				orderFunction:function(e,orderStatusName){
					//初始化加载提示
					loader.init();
					get('/order/client-order/list/'+getParameter('mobile')+'?currentPage=1',{},function(res){
						vm.orders=vm.orders.concat(res.data.resultList);

						vm.userName=res.data.resultList[0].userName;
						vm.mobile='tel:'+res.data.resultList[0].userPhone;
						vm.mobile2=res.data.resultList[0].userPhone;
						vm.mobile3=res.data.resultList[0].userPhone.replace(/^(\d{3})\d{4}(\d+)/,"$1****$2");
						vm.mess='sms:'+res.data.resultList[0].userPhone;
						vm.pictrue=res.data.pictrue ? domain+res.data.pictrue : '../../build/images/touxiang.png';
						vm.totalCount=res.data.totalCount;
						vm.orderStatusName=orderStatusName;
						vm.pageSize=res.data.pageSize;
						vm.pageCount=Math.ceil(vm.totalCount / vm.pageSize);
						for(i=0;i<vm.orders.length;i++){
							if(! vm.orders[i].insureStatus){
								vm.orders[i].insureStatus='--'
							}
						};
						//滚动到底部文字判断
						if(res.data.resultList.length < 7){
							refreshText('到底了哦！')
						}else{
							refreshText('上拉加载更多数据')
						}
						if(vm.totalCount == 0){
							$('.cus-no').show();
							$('.cus-in').hide();
							// document.querySelector('.empetDate').style.display = 'block';
							refreshText('')
						}else{
							$('.cus-no').hide();
							$('.cus-in').show();
							// document.querySelector('.empetDate').style.display = 'none';
						}
						if(vm.orders.length <7){
							refreshText('')
						}
						loader.remove();
					});
				},


				refreshData:function(){
					return function(){
						if($('.cus-con').css('display')=='block'){
							if(vm.pageCount>vm.page){
								vm.page++;
								vm.customer();
							}else{
								refreshText('到底了哦！')
							}
						}
					}
				},

				// 邀请码
				invite_code:function(){
					noParamsGet('/advisor/my-invitaion-code',function(res){
						vm.myInvitationCode=res.data.myInvitationCode;
						vm.myInvitationCodeImg=res.data.myInvitationCodeImg ? domain + res.data.myInvitationCodeImg : '../../../build/images/code.jpg';
						vm.myInvitationName=res.data.name;
					})
				},

				weixin:function(){
					$('.jump-bg').show();
					$('.invite-jump-wrap').show();
				},
				//跳转详情
				toUrl:function(mobile,url){
					window.location.href=url+'?mobile='+mobile;
				},
				toProduct:function(idStr){
					window.location.href='/pages/product/product_4_detail.html'+'?idStr='+idStr;
				},
			},
		})